package com.kuangstudy.collection.collections;

import com.sun.media.sound.SoftTuning;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * ClassName: UnsafeBuyTicket
 * date: 2021/07/13 22:32:54
 *
 * @author zlk
 */
public class Demo1 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(12);
        list.add(4);
        list.add(9);
        System.out.println(list);
        //sort排序
        Collections.sort(list);
        System.out.println(list);
        //查找
        int i = Collections.binarySearch(list, 12);
        System.out.println(i);
        //复制
        List<Integer> list2 = new ArrayList<>();
        for (int j = 0; j < list.size(); j++) {
            list2.add(0);
        }
        Collections.copy(list2,list);
        System.out.println(list2);
        //反转
        Collections.reverse(list);
        System.out.println(list);
        //洗牌
        Collections.shuffle(list);
        System.out.println(list);
        //list转为数组
        Integer[] array = (Integer[]) list.toArray(new Integer[0]);
        System.out.println(array.length);
        System.out.println(Arrays.toString(array));
        //数组转为集合
        String[] names = {"kk1","kk2","kk3"};
        /*受限集合不能添加和删除*/
        List<String> strings = Arrays.asList(names);
        System.out.println(strings);
        /*把基本类型数组转换成集合时需要修改为包装类型*/
        Integer[] nums = {100,200,300};
        List<Integer> list1 = Arrays.asList(nums);
        System.out.println(list1);

    }
}
